#include <iostream>
#include <algorithm>

using namespace std;

//vector中存放自定义数据类型，并打印输出
class Person {
public:
    string name;
    int age;

    Person(string name, int age) {
        this->name = name;
        this->age = age;
    }
};

void test1() {
    vector<Person> v;
    Person p1("aaa", 10);//创建数据
    Person p2("bbb", 20);
    Person p3("ccc", 30);
    Person p4("ddd", 40);
    Person p5("eee", 50);

    v.push_back(p1);// 直接追加
    v.push_back(p2);
    v.push_back(p3);
    v.push_back(p4);
    v.push_back(p5);

    for (vector<Person>::iterator it = v.begin(); it != v.end(); ++it) {
        cout << "name:" << it->name << ",age:" << it->age << endl;
    }
}

void test2() {
    vector<Person *> v;
    Person p1("aaa", 10);//创建数据
    Person p2("bbb", 20);
    Person p3("ccc", 30);
    Person p4("ddd", 40);
    Person p5("eee", 50);

    v.push_back(&p1);// 存放的是指针的地址
    v.push_back(&p2);
    v.push_back(&p3);
    v.push_back(&p4);
    v.push_back(&p5);

    for (vector<Person *>::iterator it = v.begin(); it != v.end(); ++it) {
        cout << "name:" << (*it)->name << ",age:" << (*it)->age << endl;
    }
}

int main() {
    test1();
    cout << "=========" << endl;
    test2();
    return 0;
}